package larrys.pomodoro.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import larrys.pomodoro.Constant;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ActiveCheckTag extends SimpleTagSupport {

	private static Log logger = LogFactory.getLog(ActiveCheckTag.class);

	private String equalsTo;

	public String getEqualsTo() {
		return equalsTo;
	}

	public void setEqualsTo(String equalsTo) {
		this.equalsTo = equalsTo;
	}

	public void doTag() throws JspException {

		PageContext pageContext = (PageContext) getJspContext();
		JspWriter out = pageContext.getOut();
		try {
			Object active = pageContext.getRequest().getAttribute(
					Constant.ACTIVIE_ATTRNAME);
			if ((active instanceof String) && (active != null)) {
				if (active.toString().equals(equalsTo)) {
					out.print("active");
				}
			}
		} catch (Exception e) {
			logger.error("Exception threw in Tag Processor:[ActiveCheckTag]", e);
		}

	}
}
